#include "../source/server.hpp"

void OnConnected(const PtrConnection& conn)
{
    DBG_LOG("NEW CONNECTION:%p",conn.get());
}

void OnClosed(const PtrConnection& conn)
{
    DBG_LOG("CONNECTION CLOSED:%p",conn.get());
}

void OnMessage(const PtrConnection& conn,Buffer* buf)
{
    DBG_LOG("%s",buf->ReadPosition());
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "Hello World!!";
    conn->Send(str.c_str(),str.size());
}

int main()
{
    TcpServer server(9999);
    server.SetThreadCount(2);
    // server.EnableInactiveRelease(7);
    server.SetConnectedCallback(OnConnected);
    server.SetClosedCallback(OnClosed);
    server.SetMessageCallback(OnMessage);
    server.Start();
    return 0;
}